<!DOCTYPE html>
<html>
<head>
    <title>${sysEn}-登录</title>
     <#include "/common/com_css.ftl" >
    <style type="text/css">
        .middle-box{padding-top: 140px;}
    </style>
</head>

<body class="gray-bg">
    <div class="middle-box text-center loginscreen animated fadeInDown">
        <div>
            <div>
                <img src="img/logo1.png" alt="ACDelco"></img>
            </div>
            <form class="m-t" role="form" id="actForm" action="/security/login.ahtml">
                <div class="form-group">
                    <input type="text" class="form-control" data-easyform="" data-message="用户名必须输入"  id="userName" name="username" placeholder="请输入用户名" >
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" id="password" data-easyform="" data-message="密码必须输入" placeholder="请输入密码" >
                </div>
                <div class="form-group form-horizontal">

                    <div class="col-lg-8" style="padding-left: 0;float:left;">
                        <input type="text" class="form-control" id="captcha" name="captcha" placeholder="请输入验证码" data-easyform="" data-message="验证码必须输入"/>
                    </div>
                    <label class="col-lg-4" style="padding: 0;cursor:pointer;float:left;" id="captchaImg">
                        <img id="captchaCode" src="${ctx}/kaptcha" style="width: 100px;height: 33px"/>
                    </label>
                </div>
                <input name="p5" type="hidden" value="${p5 }" />
                <input type="hidden" name="password" id="passwordRsa">
                <button type="button" id="loginBtn" class="btn btn-primary block full-width m-b">Login</button>
            </form>
            <p class="m-t"> <small> &copy; ${domainEn}</small> </p>
        </div>
    </div>

    <!-- Mainly scripts -->
    <script src="${ctx}/js/jquery-3.1.1.min.js"></script>
    <script src="${ctx}/js/bootstrap.js"></script>
    <!-- 加密 -->
    <script type="text/javascript" src="${ctx}/js/security/RSA.js"></script>
    <script type="text/javascript" src="${ctx}/js/security/BigInt.js"></script>
    <script type="text/javascript" src="${ctx}/js/security/Barrett.js"></script>
    <script type="text/javascript" src="${ctx}/js/security/jQuery.md5.js"></script>
    <script type="text/javascript" src="${ctx}/js/easyform/easyform.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            var vform = $("#actForm").easyform();
            vform.is_submit = false;
            vform.success=function (ef) {
                encryptString($("#userName").val(),$("#password").val());
                var jsonData = $("#actForm").serializeArray();
                $.ajax({
                    url:"/security/login.ahtml",
                    type:"post",
                    data:jsonData,
                    success:function (data) {
                        if(data.success){
                            location.href="/admin/index";
                        }
                    }
                });
            }

            $("#loginBtn").on("click",function () {
                vform.submit(false);
            });
            // 键盘登陆事件
            $("#password,#yzm").keyup(function(e){
                var currKey=0,e=e||event;
                currKey=e.keyCode||e.which||e.charcode;
                if (currKey==13){
                    $("#loginBtn").click();
                    return false;
                }
            });
            $("#captchaCode").click(function(){
                var now = new Date();
                $('#captchaCode').attr("src", '${ctx}/kaptcha?code=' + now.getTime());
            });
        });

        function encryptString(userName, password) {
            if(userName!=''&&password!=''){
                password = $.md5(password);
                setMaxDigits(130);
                var key = key = new RSAKeyPair("${e}","","${m}");
                var passwordRsa = encryptedString(key, password);
                $("#passwordRsa").val(passwordRsa);
            }
        }
    </script>
</body>
</html>
